var balanceInitSettingData = [];
var deleteFlag = undefined;

//查询
$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	$("#change").show();
    $("#save").hide();
	search();
});

function search(){
	setFormDisabled("saveForm");
	$ajax('searchBalanceInitSetting', '', searchBalanceSet);
}
function searchBalanceSet(data){
	balanceInitSettingData = data && data.balanceInitSettingList || [];
	if(balanceInitSettingData.length == 0){
		$("#balanceStartMonth").val(new Date().getFullYear() + "01");
		$("#balanceDay").val("01");
		$("#defaultServicePriceRate").val("0.15");
		$("#fixedRatio").attr("hidden", false);
		$("#defaultFixedRatio").val("1");
		return;
	}
	$("#balanceStartMonth").val(balanceInitSettingData[0].balanceStartMonth || new Date().getFullYear() + "01");
	$("#balanceDay").val(balanceInitSettingData[0].balanceDay || "01");
	$("#balanceRatioType").val(balanceInitSettingData[0].balanceRatioType || "3");
	if(balanceInitSettingData[0].balanceRatioType == "1"){
		$("#fixedRatio").attr("hidden", false);
		$("#defaultFixedRatio").val(balanceInitSettingData[0].defaultFixedRatio || "1");
	}
	$("#balanceChargingPriceType").val(balanceInitSettingData[0].balanceChargingPriceType || "2");
	$("#balanceBusPriceType").val(balanceInitSettingData[0].balanceBusPriceType || "1");
	$("#defaultServicePriceRate").val(balanceInitSettingData[0].defaultServicePriceRate || "0.15");
}
function changeRatio(){
	var balanceRatio = $("#balanceRatioType").val();
	if(balanceRatio == "1"){
		$("#fixedRatio").attr("hidden", false);
	} else {
		$("#fixedRatio").attr("hidden", true);
	}
}
function change() {
	deleteFlag = "update";
    $("#balanceStartMonth").attr("disabled", false);
	$("#balanceDay").attr("disabled", false);
	$("#balanceRatioType").attr("disabled", false);
	$("#defaultFixedRatio").attr("disabled", false);
	$("#balanceChargingPriceType").attr("disabled", false);
	$("#balanceBusPriceType").attr("disabled", false);
	$("#defaultServicePriceRate").attr("disabled", false);
    $("#save").show();
    $("#change").hide();
}
function saveSetting(data){
	var result = data && data.result;
	if (result == "Success"){
		showMessge("修改成功");
		setFormDisabled("saveForm");
	    $("#save").hide();
	    $("#change").show();
	} else if (result == "NotFound"){
		showMessge("修改失败");	
	} else{
		showMessge("修改异常");
	}
}
function getUrl(){
	if(deleteFlag == "update"){
		return 'updateBalanceInitSetting';
	}
}
function confirm(){
	if(deleteFlag == "update"){
		return checkForm("saveForm");
	}
}
function resetAuthority(){
	$ajax('resetAuthority', '', resetAuthorityBack);
}
function resetAuthorityBack(data){
	if(data.result == "Success"){
		showMessge("重置成功");
	} else {
		showMessge("重置失败");
	}
}

function toPercent(point){
    var str=Number(point*100).toFixed(1);
    str+="%";
    return str;
}